package astroH;



import com.sun.lwuit.Graphics;
import com.sun.lwuit.Image;
import java.util.Calendar;
import java.util.Date;
//import javax.microedition.lcdui.Graphics;
//import javax.microedition.lcdui.Image;

public class LunarPhases {

    final double TwoPi = 6.2831853071795862D;
    final double radian = 0.017453292519943295D;
    private int borderWidth;
    String phaseTime[] = {
        "", "", "", ""
    };
    int moonPhase[] = {
        0, 1, 2, 3
    };
    Graphics offScreenGraphics;
    Image img;
    Image homePage;
    Image aboutIcon;
    int imgradius;
    int imgHeight;
    public int K;
    public long offsetMillis = 0;
    public boolean usingFixedDate = false;
    public Date fixedDate;
    int day;
    int month;
    public int year;
    int hour;
    int minute;
    int second;
    public String gmt;
    private String monthNames;
    double JDjan1;
    double JDnow;
    double JDtm;
    double decimalYear;
    int PhaseCounter;
    double L1;
    double M;
    double M1;
    double d;
    double F;
    double OM;
    double LunarLong;
    double LunarLat;
    double LunarRA;
    double LunarDec;
    double SolarLong;
    double SolarRA;
    double SolarDec;
    double OblEclip;
    double T;
    private Thread gmtThread;
    private boolean isRunning;
    public long ms;
    private int moonWidth;
    String phaseDesc;
    String lunarApogee;
    String lunarPerigee;
    long PerigeeDistance;
    long ApogeeDistance;
    long distance;
    String AgeOfMoon;
    boolean about;
//    MediaTracker LoadImages;
    double JDNextNewMoon;
    double JDLastNewMoon;
    
    public void init()
    {
        gmtThread = null;
//        resize(preferredDimension);
//        setBackground(Color.black);
//        setForeground(Color.white);
//        Dimension dimension = size();
//        offScreenImage = createImage(dimension.width, dimension.height);
//        offScreenSize = dimension;
//        offScreenGraphics = offScreenImage.getGraphics();
//        moonFont = new Font("Helvetica", 0, 11);
//        offScreenGraphics.setFont(moonFont);
//        moonFontMetrics = getGraphics().getFontMetrics();
//        LoadImages = new MediaTracker(this);
//        moonImage = getImage(getCodeBase(), "moon2.gif");
//        LoadImages.addImage(moonImage, 0);
//        phaseImage[0] = getImage(getCodeBase(), "nm.gif");
//        LoadImages.addImage(phaseImage[0], 0);
//        phaseImage[3] = getImage(getCodeBase(), "lq.gif");
//        LoadImages.addImage(phaseImage[3], 0);
//        phaseImage[2] = getImage(getCodeBase(), "fm.gif");
//        LoadImages.addImage(phaseImage[2], 0);
//        phaseImage[1] = getImage(getCodeBase(), "fq.gif");
//        LoadImages.addImage(phaseImage[1], 0);
//        homePage = getImage(getCodeBase(), "home.gif");
//        LoadImages.addImage(homePage, 0);
//        aboutIcon = getImage(getCodeBase(), "about.gif");
//        LoadImages.addImage(aboutIcon, 0);
//        try
//        {
//            LoadImages.waitForID(0);
//        }
//        catch(InterruptedException _ex)
//        {
//            System.out.println("Image Loading Failed!");
//        }
//        lunarPosition();
//        CalcLunarPhases();
//        getApogeePerigee();
//        repaint();
//        LoadImages.checkID(0, true);
    }

//    public void paint(Graphics g)
//    {
//        offScreenGraphics.setColor(Color.black);
//        if(!about)
//        {
//            offScreenGraphics.fillRect(0, 0, offScreenSize.width, offScreenSize.height);
//            offScreenGraphics.drawImage(homePage, 6, offScreenSize.height - 22, this);
//            offScreenGraphics.drawImage(aboutIcon, 32, offScreenSize.height - 23, this);
//            offScreenGraphics.drawImage(moonImage, 10, 15, this);
//            drawBorder(offScreenGraphics);
//            drawMoon(offScreenGraphics, K, year);
//            drawSeparator(offScreenGraphics);
//            offScreenGraphics.setColor(new Color(210, 245, 210));
//            for(int i = 0; i < 4; i++)
//            {
//                offScreenGraphics.drawImage(phaseImage[moonPhase[i]], 260, 36 * i + 10, this);
//                offScreenGraphics.drawString(phaseTime[i], 300, 36 * i + 30);
//            }
//
//            offScreenGraphics.drawString(gmt, 51 + (200 - moonFontMetrics.stringWidth(gmt)) / 2, 150);
//            offScreenGraphics.setColor(new Color(255, 255, 255));
//            offScreenGraphics.drawString(phaseDesc, 134, 18);
//            offScreenGraphics.setColor(new Color(0, 245, 255));
//            offScreenGraphics.drawString("Visible: ", 134, 36);
//            offScreenGraphics.drawString("Age:", 134, 50);
//            offScreenGraphics.drawString("Distance: ", 134, 64);
//            offScreenGraphics.drawString("Apogee: ", 134, 83);
//            offScreenGraphics.drawString("Perigee: ", 134, 112);
//            offScreenGraphics.setColor(new Color(210, 245, 210));
//            offScreenGraphics.drawString("" + K + "%", 182, 36);
//            offScreenGraphics.drawString(AgeOfMoon, 182, 50);
//            offScreenGraphics.drawString("" + distance + " km", 182, 64);
//            offScreenGraphics.drawString(lunarApogee, 182, 83);
//            offScreenGraphics.drawString("" + ApogeeDistance + " km", 182, 96);
//            offScreenGraphics.drawString(lunarPerigee, 182, 112);
//            offScreenGraphics.drawString("" + PerigeeDistance + " km", 182, 125);
//        } else
//        {
//            offScreenGraphics.fillRect(borderWidth, borderWidth, 246, 128);
//            offScreenGraphics.setColor(new Color(255, 255, 255));
//            offScreenGraphics.drawString("This applet displays the current phase of the", 10, 18);
//            offScreenGraphics.drawString("moon and the time/date of the next four major", 10, 30);
//            offScreenGraphics.drawString("lunar phases. The current age of the moon, its", 10, 42);
//            offScreenGraphics.drawString("distance and apogee/perigee dates are also ", 10, 54);
//            offScreenGraphics.drawString("displayed. ", 10, 66);
//            offScreenGraphics.drawString("All times displayed are in UT except for the", 10, 92);
//            offScreenGraphics.drawString("clock which displays the local time.", 10, 104);
//            offScreenGraphics.drawString("Click ? to return to display.", 10, 128);
//        }
//        g.drawImage(offScreenImage, 0, 0, this);
//    }

    public String CalDate(double d1)
    {
        d1 += 0.5D;
        long l = (long)d1;
        double d2 = d1 - (double)l;
        long l1;
        if(l < 0x231519L)
        {
            l1 = l;
        } else
        {
            int i = (int)(((double)l - 1867216.25D) / 36524.25D);
            l1 = (l + 1L + (long)i) - (long)(i / 4);
        }
        long l2 = l1 + 1524L;
        int i2 = (int)(((double)l2 - 122.09999999999999D) / 365.25D);
        long l3 = (int)(365.25D * (double)i2);
        int j2 = (int)((double)(l2 - l3) / 30.600100000000001D);
        double d3 = (double)(l2 - l3 - (long)(int)(30.600100000000001D * (double)j2)) + d2;
        int i1 = (int)d3;
        d3 = (d3 - (double)i1) * 24D;
        int j = (int)d3;
        d3 = (d3 - (double)j) * 60D;
        int k = (int)d3;
        int j1;
        if(j2 <= 13)
            j1 = j2 - 1;
        else
            j1 = j2 - 13;
        int k1;
        if(j1 <= 2)
            k1 = i2 - 4715;
        else
            k1 = i2 - 4716;
        String s1;
        if(j < 10)
            s1 = "0" + j;
        else
            s1 = "" + j;
        String s2;
        if(k < 10)
            s2 = "0" + k;
        else
            s2 = "" + k;
        String s = s1 + ":" + s2 + " " + i1 + " " + monthNames.substring(--j1 * 3, j1 * 3 + 3) + " " + k1;
        return s;
    }

    public double julianDay(int i, int j, int k, int l, int i1, int j1)
    {
        double d3 = l * 3600 + i1 * 60 + j1;
        double d1 = (double)i + d3 / 86400D;
        if(j <= 2)
        {
            j += 12;
            k--;
        }
        int k1 = k / 100;
        int l1 = (2 - k1) + k1 / 4;
        double d2 = (double)((long)(365.25D * (double)(k + 4716)) + (long)(int)(30.600100000000001D * (double)(j + 1))) + d1 + (double)l1 + -1524.5D;
        return d2;
    }

    public double reduce(double d1)
    {
        d1 -= 6.2831853071795862D * (double)(int)(d1 / 6.2831853071795862D);
        if(d1 < 0.0D)
            d1 += 6.2831853071795862D;
        return d1;
    }

    public double rad(double d1)
    {
        return d1 * 0.017453292519943295D;
    }

    public double Deg(double d1)
    {
        return (d1 * 180D) / 3.1415926535897931D;
    }

    public int CalcLunarPhases()
    {
        new Date();
        int j1 = 0;
        double d1 = getDateAndTime();
        int j = month + 1;
        int k;
        if(j <= 12)
        {
            k = year;
        } else
        {
            boolean flag = true;
            int l = year + 1;
        }
        double d3 = (d1 - 2000D) * 12.368499999999999D * 4D;
        d3 = (int)d3;
        double d2 = d3 / 4D - 0.5D;
        int i = 0;
        do
        {
            double d5 = Math.abs(d2 - (double)(int)d2);
            moonPhase[i] = (int)(4D * d5);
            double d4 = getMoonJD(d2, d5);
            if(d4 >= JDnow)
            {
                String s = CalDate(d4);
                if(s.length() != 17)
                    s = s.substring(0, 6) + "0" + s.substring(6, 16);
                phaseTime[i] = s;
                int i1 = (int)(4D * d5) % 4;
                i++;
                if(d2 - (double)(int)d2 == 0.0D)
                {
                    JDNextNewMoon = d4;
                    j1 = (int)d2 - 1;
                }
            }
            d2 += 0.25D;
        } while(i < 4);
        JDLastNewMoon = getMoonJD(j1, 0.0D);
        return i;
    }

    public void leftShadow(int i, int j, Graphics g)
    {
        g.setColor(0x202020);
        int k;
        int l;
        if(j == 1)
        {
            k = i;
            l = 50;
        } else
        {
            k = 0;
            l = i;
        }
        for(int j1 = k; j1 <= l; j1++)
        {
            //double d1 = acos(1.0D - ((double)j1 * 2D) / 100D);
            //int i1 = (int)(101D * Math.cos(d1));
            int i1 = (int)(101D * (1.0D - ((double)j1 * 2D) / 100D));
            g.drawArc(((101 - i1)) / 2, 0, i1, 101, 90, 180);
        }

    }

    public void rightShadow(int i, int j, Graphics g)
    {
        g.setColor(0x202020);
        int k;
        int l;
        if(j == 0)
        {
            k = i;
            l = 50;
        } else
        {
            k = 0;
            l = i;
        }
        for(int j1 = k; j1 <= l; j1++)
        {
            //double d1 = acos(1.0D - ((double)j1 * 2D) / 100D);
            //int i1 = (int)(101D * Math.cos(d1));
            int i1 = (int)(101D * (1.0D - ((double)j1 * 2D) / 100D));
            g.drawArc(((101 - i1)) / 2, 0, i1, 101, 270, 180);
        }

    }

       public void drawMoon(Graphics g, int i, int j)
    {
        double d1 = JDnow - JDLastNewMoon;
        AgeOfMoon = "" + (int)d1 + "d ";
        d1 = (d1 - (double)(int)d1) * 24D;
        AgeOfMoon = AgeOfMoon + (int)d1 + "h ";
        d1 = (d1 - (double)(int)d1) * 60D;
        AgeOfMoon = AgeOfMoon + (int)d1 + "m";
        d1 = JDnow - JDLastNewMoon;
        int k = (int)((d1 / (JDNextNewMoon - JDLastNewMoon)) * 100D + 0.5D);
        if(k == 0)
        {
            phaseDesc = "New Moon";
            leftShadow(50, 0, g);
            rightShadow(50, 1, g);
            return;
        }
        if(k < 24)
        {
            phaseDesc = "Waxing Crescent";
            leftShadow(50, 0, g);
            rightShadow(i, 0, g);
            return;
        }
        if(k < 26)
        {
            phaseDesc = "First Quarter";
            leftShadow(100 - i, 0, g);
            return;
        }
 
        if(k < 49)
        {
            phaseDesc = "Waxing Gibbous";
            leftShadow(100 - i, 0, g);
            return;
        }
        if(k < 52)
        {
            phaseDesc = "Full Moon";
            return;
        }
        if(k < 75)
        {
            phaseDesc = "Waning Gibbous";
            rightShadow(100 - i, 1, g);
            return;
        }
        if(k < 78)
        {
            phaseDesc = "Last Quarter";
            rightShadow(50, 1, g);
            return;
        }
        if(k < 100)
        {
            phaseDesc = "Waning Crescent";
            leftShadow(i, 1, g);
            rightShadow(50, 1, g);
            return;
        } else
        {
            phaseDesc = "New Moon";
            leftShadow(50, 0, g);
            rightShadow(50, 1, g);
            return;
        }
    }
       
//    public void drawPhase(Graphics g, int i)
//    {
//        g.drawImage(phaseImage[i], 30, 30 * i, this);
//    }
//
//    public void drawBorder(Graphics g)
//    {
//        g.setColor(new Color(0, 183, 255));
//        g.drawLine(0, offScreenSize.height, 0, 0);
//        g.drawLine(0, 0, offScreenSize.width, 0);
//        g.drawLine(offScreenSize.width - borderWidth, borderWidth - 1, offScreenSize.width - borderWidth, offScreenSize.height - borderWidth);
//        g.setColor(new Color(0, 183, 255));
//        g.drawLine(offScreenSize.width - borderWidth, offScreenSize.height - borderWidth, borderWidth - 1, offScreenSize.height - borderWidth);
//        g.setColor(new Color(0, 87, 175));
//        g.drawLine(offScreenSize.width - 1, 0, offScreenSize.width - 1, offScreenSize.height - 1);
//        g.drawLine(offScreenSize.width - 1, offScreenSize.height - 1, 1, offScreenSize.height - 1);
//        g.drawLine(borderWidth - 1, offScreenSize.height - borderWidth - 1, borderWidth - 1, borderWidth - 1);
//        g.drawLine(borderWidth - 1, borderWidth - 1, offScreenSize.width - borderWidth - 1, borderWidth - 1);
//        g.setColor(new Color(0, 127, 255));
//        for(int i = 1; i <= borderWidth - 2; i++)
//            g.drawRect(i, i, offScreenSize.width - 1 - 2 * i, offScreenSize.height - 1 - 2 * i);
//
//    }

//    public void drawSeparator(Graphics g)
//    {
//        int i = (5 * preferredDimension.height) / 6;
//        g.setColor(new Color(0, 127, 255));
//        g.drawLine(borderWidth - 1, i, 250, i);
//        g.setColor(new Color(0, 87, 175));
//        g.drawLine(borderWidth - 1, i + 1, 250, i + 1);
//        g.setColor(new Color(0, 127, 255));
//        g.drawLine(25, i + 2, 25, offScreenSize.height - 1 - borderWidth);
//        g.setColor(new Color(0, 87, 175));
//        g.drawLine(26, i + 2, 26, offScreenSize.height - 1 - borderWidth);
//        g.setColor(new Color(0, 127, 255));
//        g.drawLine(50, i + 2, 50, offScreenSize.height - 1 - borderWidth);
//        g.setColor(new Color(0, 87, 175));
//        g.drawLine(51, i + 2, 51, offScreenSize.height - 1 - borderWidth);
//        g.setColor(new Color(0, 127, 255));
//        g.drawLine(250, borderWidth, 250, offScreenSize.height - 1 - borderWidth);
//        g.setColor(new Color(0, 87, 175));
//        g.drawLine(251, borderWidth, 251, offScreenSize.height - 1 - borderWidth);
//    }

    public void lunarPosition()
    {
        decimalYear = getDateAndTime();

        String s = "" + hour;
        String s1 = "" + minute;
        String s2 = "" + second;
        if(hour < 10)
            s = "0" + hour;
        if(minute < 10)
            s1 = "0" + minute;
        if(second < 10)
            s2 = "0" + second;
        gmt = s + ":" + s1 + ":" + s2 + "  " + day + " " + monthNames.substring((month - 1) * 3, month * 3) + " " + year;
        JDnow = julianDay(day, month, year, hour, minute, second);
        T = (JDnow - 2415020D) / 36525D;
        double d15 = T * T;
        double d16 = d15 * T;
        OblEclip = (23.439291110999999D - 0.0130041666D * T - 1.6389999E-006D * d15) + 5.0361109999999996E-007D * d16;
        double d7 = 1.0D - 0.0024949999999999998D * T - 7.52E-006D * d15;
        L1 = ((270.43416400000001D + 481267.88309999998D * T) - 0.0011329999999999999D * d15) + 1.9E-006D * d16;
        M = (358.47583300000002D + 35999.049800000001D * T) - 0.00014999999999999999D * d15 - 3.3000000000000002E-006D * d16;
        M1 = 296.10460799999998D + 477198.84909999999D * T + 0.0091920000000000005D * d15 + 1.4399999999999999E-005D * d16;
        d = ((350.73748599999999D + 445267.11420000001D * T) - 0.001436D * d15) + 1.9000000000000001E-005D * d16;
        F = (11.250889000000001D + 483202.02510000003D * T) - 0.0032109999999999999D * d15 - 2.9999999999999999E-007D * d16;
        OM = (259.18327499999998D - 1934.1420000000001D * T) + 0.002078D * d15 + 2.2000000000000001E-006D * d16;
        double d1 = Math.sin(rad(51.200000000000003D + 20.199999999999999D * T));
        double d2 = Math.sin(rad(OM));
        double d3 = 0.0039639999999999996D * Math.sin(rad((346.56D + 132.87D * T) - 0.0091731D * d15));
        L1 = L1 + 0.000233D * d1 + 0.001964D * d2 + d3;
        M = M - 0.0017780000000000001D * d1;
        M1 = M1 + 0.00081700000000000002D * d1 + 0.0025409999999999999D * d2 + d3;
        d = d + 0.0020110000000000002D * d1 + 0.001964D * d2 + d3;
        F = (F - 0.024691000000000001D * d2 - 0.0043280000000000002D * Math.sin(rad((OM + 275.05000000000001D) - 2.2999999999999998D * T))) + d3;
        M = reduce(rad(M));
        M1 = reduce(rad(M1));
        d = reduce(rad(d));
        F = reduce(rad(F));
        OM = reduce(rad(OM));
        double d17 = 2D * d;
        double d18 = 2D * M1;
        double d19 = 2D * F;
        double d20 = 2D * M;
        double d21 = 4D * d;
        LunarLong = ((((((((((((((((((L1 + 6.2887500000000003D * Math.sin(M1) + 1.2740180000000001D * Math.sin(d17 - M1) + 0.65830900000000003D * Math.sin(d17) + 0.213616D * Math.sin(d18)) - 0.18559600000000001D * Math.sin(M) * d7 - 0.11433599999999999D * Math.sin(d19)) + 0.058792999999999998D * Math.sin(d17 - d18) + 0.057211999999999999D * Math.sin(d17 - M - M1) * d7 + 0.053319999999999999D * Math.sin(d17 + M1) + 0.045873999999999998D * Math.sin(d17 - M) * d7 + 0.041023999999999998D * Math.sin(M1 - M) * d7) - 0.034717999999999999D * Math.sin(d) - 0.030464999999999999D * Math.sin(M + M1) * d7) + 0.015325999999999999D * Math.sin(d17 - d19)) - 0.012527999999999999D * Math.sin(d19 + M1) - 0.01098D * Math.sin(d19 - M1)) + 0.010673999999999999D * Math.sin(d21 - M1) + 0.010034D * Math.sin(3D * M1) + 0.008548D * Math.sin(d21 - d18)) - 0.0079100000000000004D * Math.sin((M - M1) + d17) * d7 - 0.006783D * Math.sin(d17 + M) * d7) + 0.0051619999999999999D * Math.sin(M1 - d) + 0.0050000000000000001D * Math.sin(M + d) * d7 + 0.0040489999999999996D * Math.sin((M1 - M) + d17) * d7 + 0.0039960000000000004D * Math.sin(d18 + d17) + 0.003862D * Math.sin(d21) + 0.0036649999999999999D * Math.sin(d17 - 3D * M1) + 0.0026949999999999999D * Math.sin(d18 - M) * d7 + 0.0026020000000000001D * Math.sin(M1 - d19 - d17) + 0.0023960000000000001D * Math.sin(d17 - M - d18) * d7) - 0.002349D * Math.sin(M1 + d)) + 0.0022490000000000001D * Math.sin(d17 - d20) * d7 * d7) - 0.0021250000000000002D * Math.sin(d18 + M) * d7 - 0.0020790000000000001D * Math.sin(d20) * d7 * d7) + 0.0020590000000000001D * Math.sin(d17 - M1 - d20) * d7 * d7) - 0.0017730000000000001D * Math.sin((M1 + d17) - d19) - 0.0015950000000000001D * Math.sin(d19 + d17)) + 0.0012199999999999999D * Math.sin(d21 - M - M1) * d7) - 0.0011100000000000001D * Math.sin(d18 + d19)) + 0.000892D * Math.sin(M1 - 3D * d)) - 0.00081099999999999998D * Math.sin(M + M1 + d17) * d7) + 0.00076099999999999996D * Math.sin(d21 - M - d18) * d7 + 0.00071699999999999997D * Math.sin(M1 - d20) * d7 * d7 + 0.00070399999999999998D * Math.sin(M1 - d20 - d17) * d7 * d7 + 0.00069300000000000004D * Math.sin((M - d18) + d17) * d7 + 0.00059800000000000001D * Math.sin(d17 - M - d19) * d7 + 0.00055000000000000003D * Math.sin(M1 + d21) + 0.00053799999999999996D * Math.sin(4D * M1) + 0.00052099999999999998D * Math.sin(d21 - M) * d7 + 0.000486D * Math.sin(d18 - d);
        double d4 = (((((((5.1281889999999999D * Math.sin(F) + 0.28060600000000002D * Math.sin(M1 + F) + 0.27769300000000002D * Math.sin(M1 - F) + 0.173238D * Math.sin(d17 - F) + 0.055412999999999997D * Math.sin((d17 + F) - M1) + 0.046272000000000001D * Math.sin(d17 - F - M1) + 0.032572999999999998D * Math.sin(d17 + F) + 0.017198000000000001D * Math.sin(d18 + F) + 0.0092669999999999992D * Math.sin((d17 + M1) - F) + 0.0088229999999999992D * Math.sin(d18 - F) + 0.0082470000000000009D * Math.sin(d17 - M - F) * d7 + 0.0043229999999999996D * Math.sin(d17 - F - d18) + 0.0041999999999999997D * Math.sin(d17 + F + M1) + 0.003372D * Math.sin(F - M - d17) * d7 + 0.0024719999999999998D * Math.sin((d17 + F) - M - M1) * d7 + 0.002222D * Math.sin((d17 + F) - M) * d7 + 0.0020720000000000001D * Math.sin(d17 - F - M - M1) * d7 + 0.001877D * Math.sin((F - M) + M1) * d7 + 0.001828D * Math.sin(d21 - F - M1)) - 0.0018029999999999999D * Math.sin(F + M) * d7 - 0.00175D * Math.sin(3D * F)) + 0.00157D * Math.sin(M1 - M - F) * d7) - 0.001487D * Math.sin(F + d) - 0.0014809999999999999D * Math.sin(F + M + M1) * d7) + 0.0014170000000000001D * Math.sin(F - M - M1) * d7 + 0.0013500000000000001D * Math.sin(F - M) * d7 + 0.00133D * Math.sin(F - d) + 0.001106D * Math.sin(F + 3D * M1) + 0.0010200000000000001D * Math.sin(d21 - F) + 0.00083299999999999997D * Math.sin((F + d21) - M1) + 0.00078100000000000001D * Math.sin(M1 - 3D * F) + 0.00067000000000000002D * Math.sin((F + d21) - d18) + 0.00060599999999999998D * Math.sin(d17 - 3D * F) + 0.00059699999999999998D * Math.sin((d17 + d18) - F) + 0.00049200000000000003D * Math.sin((d17 + M1) - M - F) * d7 + 0.00044999999999999999D * Math.sin(d18 - F - d17) + 0.00043899999999999999D * Math.sin(3D * M1 - F) + 0.00042299999999999998D * Math.sin(F + d17 + d18) + 0.00042200000000000001D * Math.sin(d17 - F - 3D * M1)) - 0.00036699999999999998D * Math.sin((M + F + d17) - M1) * d7 - 0.00035300000000000002D * Math.sin(M + F + d17) * d7) + 0.00033100000000000002D * Math.sin(F + d21) + 0.00031700000000000001D * Math.sin(((d17 + F) - M) + M1) * d7 + 0.00030600000000000001D * Math.sin(d17 - d20 - F) * d7 * d7) - 0.00028299999999999999D * Math.sin(M1 + 3D * F);
        double d5 = 0.00046640000000000001D * Math.cos(OM);
        double d6 = 7.5400000000000003E-005D * Math.cos(OM + rad(275.05000000000001D - 2.2999999999999998D * T));
        LunarLong = reduce(rad(LunarLong));
        LunarLat = rad(d4 * (1.0D - d5 - d6));
        double d14 = ((((((((((((0.95072400000000001D + 0.051818000000000003D * Math.cos(M1) + 0.0095309999999999995D * Math.cos(d17 - M1) + 0.0078429999999999993D * Math.cos(d17) + 0.0028240000000000001D * Math.cos(d18) + 0.00085700000000000001D * Math.cos(d17 + M1) + 0.00053300000000000005D * Math.cos(d17 - M) * d7 + 0.00040099999999999999D * Math.cos(d17 - M - M1) * d7 + 0.00032000000000000003D * Math.cos(M1 - M) * d7) - 0.00027099999999999997D * Math.cos(d) - 0.00026400000000000002D * Math.cos(M + M1) * d7 - 0.00019799999999999999D * Math.cos(d19 - M1)) + 0.000173D * Math.cos(3D * M1) + 0.00016699999999999999D * Math.cos(d21 - M1)) - 0.000111D * Math.cos(M) * d7) + 0.000103D * Math.cos(d21 - d18)) - 8.3999999999999995E-005D * Math.cos(d18 - d17) - 8.2999999999999998E-005D * Math.cos(d17 + M) * d7) + 7.8999999999999996E-005D * Math.cos(d17 + d18) + 7.2000000000000002E-005D * Math.cos(d21) + 6.3999999999999997E-005D * Math.cos((d17 - M) + M1) * d7) - 6.3E-005D * Math.cos((d17 + M) - M1) * d7) + 4.1E-005D * Math.cos(M + d) * d7 + 3.4999999999999997E-005D * Math.cos(d18 - M) * d7) - 3.3000000000000003E-005D * Math.cos(3D * M1 - d17) - 3.0000000000000001E-005D * Math.cos(M1 + d) - 2.9E-005D * Math.cos(d19 - d17) - 2.9E-005D * Math.cos(d18 + M) * d7) + 2.5999999999999998E-005D * Math.cos(d17 - d20) * d7 * d7) - 2.3E-005D * Math.cos((d19 - d17) + M1)) + 1.9000000000000001E-005D * Math.cos(d21 - M - M1) * d7;
        distance = (long)(6378.1400000000003D / Math.sin(rad(d14)) + 0.5D);
        double d8 = 279.69668000000001D + 36000.768920000002D * T + 0.00030249999999999998D * d15;
        double d9 = reduce(rad((358.47582999999997D + 35999.049749999998D * T) - 0.00014999999999999999D * d15 - 3.3000000000000002E-006D * d16));
        double d11 = 0.016751039999999998D - 4.18E-005D * T - 1.2599999999999999E-007D * d15;
        double d10 = (1.9194599999999999D - 0.0047889999999999999D * T - 1.4E-005D * d15) * Math.sin(d9) + (0.020094000000000001D - 0.0001D * T) * Math.sin(2D * d9) + 0.00029300000000000002D * Math.sin(3D * d9);
        double d12 = reduce(rad(d8 + d10));
        d = Astro.acos(Math.cos(LunarLong - d12) * Math.cos(LunarLat));
        double d13 = 180D - Deg(d) - 0.14680000000000001D * ((1.0D - 0.054899999999999997D * Math.sin(M1)) / (1.0D - 0.0167D * Math.sin(M1))) * Math.sin(d);
        K = (int)((1.0D + Math.cos(rad(d13))) * 50D + 0.5D);
    }
    
    public double getDateAndTime()
    {
        Date date;
        if (usingFixedDate) {
            date = fixedDate;
        }
        else {
            date = new Date(System.currentTimeMillis() + offsetMillis);
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        day = cal.get(Calendar.DAY_OF_MONTH);
        month = cal.get(Calendar.MONTH) + 1;
        year = cal.get(Calendar.YEAR);
        hour = cal.get(Calendar.HOUR_OF_DAY);
        minute = cal.get(Calendar.MINUTE);
        second = cal.get(Calendar.SECOND);
        JDjan1 = julianDay(1, 1, year, 0, 0, 0);
        JDtm = julianDay(day, month, year, hour, minute, second);
        return (double)year + (JDtm - JDjan1 - 1.0D) / 365.25D;
    }

    public double calculateMajorPhase(double d1, double d2, double d3)
    {
        double ad[][] = {
            {
                -0.40720000000000001D, -0.40614D
            }, {
                0.17241000000000001D, 0.17302000000000001D
            }, {
                0.016080000000000001D, 0.016140000000000002D
            }, {
                0.01039D, 0.01043D
            }, {
                0.0073899999999999999D, 0.0073400000000000002D
            }, {
                -0.0051399999999999996D, -0.0051500000000000001D
            }, {
                0.0020799999999999998D, 0.0020899999999999998D
            }, {
                -0.0011100000000000001D, -0.0011100000000000001D
            }, {
                -0.00056999999999999998D, -0.00056999999999999998D
            }, {
                0.00055999999999999995D, 0.00055999999999999995D
            }, {
                -0.00042000000000000002D, -0.00042000000000000002D
            }, {
                0.00042000000000000002D, 0.00042000000000000002D
            }, {
                0.00038000000000000002D, 0.00038000000000000002D
            }, {
                -0.00024000000000000001D, -0.00024000000000000001D
            }, {
                -0.00017000000000000001D, -0.00017000000000000001D
            }, {
                -6.9999999999999994E-005D, -6.9999999999999994E-005D
            }, {
                4.0000000000000003E-005D, 4.0000000000000003E-005D
            }, {
                4.0000000000000003E-005D, 4.0000000000000003E-005D
            }, {
                3.0000000000000001E-005D, 3.0000000000000001E-005D
            }, {
                3.0000000000000001E-005D, 3.0000000000000001E-005D
            }, {
                -3.0000000000000001E-005D, -3.0000000000000001E-005D
            }, {
                3.0000000000000001E-005D, 3.0000000000000001E-005D
            }, {
                -2.0000000000000002E-005D, -2.0000000000000002E-005D
            }, {
                -2.0000000000000002E-005D, -2.0000000000000002E-005D
            }, {
                2.0000000000000002E-005D, 2.0000000000000002E-005D
            }
        };
        double d11 = d3 * d3;
        double d12 = d11 * d3;
        double d13 = d12 * d3;
        double d9 = 1.0D - 0.002516D * d3 - 7.4000000000000003E-006D * d11;
        double d4 = reduce(rad((2.5533999999999999D + 29.105356690000001D * d1) - 2.1800000000000001E-005D * d11 - 1.1000000000000001E-007D * d12));
        double d5 = reduce(rad((201.5643D + 385.81693528D * d1 + 0.0107438D * d11 + 1.239E-005D * d12) - 5.8000000000000003E-008D * d13));
        double d6 = reduce(rad(((160.71080000000001D + 390.67050274000002D * d1) - 0.0016341000000000001D * d11 - 2.2699999999999999E-006D * d12) + 1.0999999999999999E-008D * d13));
        double d8 = reduce(rad((124.77460000000001D - 1.5637558D * d1) + 0.0020690999999999999D * d11 + 2.1500000000000002E-006D * d12));
        double d17 = reduce(rad((299.76999999999998D + 0.107408D * d1) - 0.0091730000000000006D * d11));
        double d18 = reduce(rad(251.88D + 0.016320999999999999D * d1));
        double d19 = reduce(rad(251.83000000000001D + 26.651886000000001D * d1));
        double d20 = reduce(rad(349.42000000000002D + 36.412478D * d1));
        double d21 = reduce(rad(84.659999999999997D + 18.206239D * d1));
        double d22 = reduce(rad(141.74000000000001D + 53.303770999999998D * d1));
        double d23 = reduce(rad(207.13999999999999D + 2.453732D * d1));
        double d24 = reduce(rad(154.84D + 7.3068600000000004D * d1));
        double d25 = reduce(rad(34.520000000000003D + 27.261239D * d1));
        double d26 = reduce(rad(207.19D + 0.121824D * d1));
        double d27 = reduce(rad(291.33999999999997D + 1.844379D * d1));
        double d28 = reduce(rad(161.72D + 24.198153999999999D * d1));
        double d29 = reduce(rad(239.56D + 25.513099D * d1));
        double d30 = reduce(rad(331.55000000000001D + 3.5925180000000001D * d1));
        double d14 = 2D * d4;
        double d15 = 2D * d5;
        double d16 = 2D * d6;
        double d7;
        if(d2 == 0.0D || d2 == 0.5D)
        {
            int i = Math.abs((int)(2D * d2));
            d7 = ad[0][i] * Math.sin(d5) + ad[1][i] * Math.sin(d4) * d9 + ad[2][i] * Math.sin(d15) + ad[3][i] * Math.sin(d16) + ad[4][i] * Math.sin(d5 - d4) + ad[5][i] * Math.sin(d5 + d4) + ad[6][i] * Math.sin(d14) + ad[7][i] * Math.sin(d5 - d16) + ad[8][i] * Math.sin(d5 + d16) + ad[9][i] * Math.sin(d15 + d4) + ad[10][i] * Math.sin(3D * d5) + ad[11][i] * Math.sin(d4 + d16) + ad[12][i] * Math.sin(d4 - d16) + ad[13][i] * Math.sin(d15 - d4) + ad[14][i] * Math.sin(d8) + ad[15][i] * Math.sin(d5 + d14) + ad[16][i] * Math.sin(d15 - d16) + ad[17][i] * Math.sin(3D * d4) + ad[18][i] * Math.sin((d5 + d4) - d16) + ad[19][i] * Math.sin(d15 + d16) + ad[20][i] * Math.sin(d5 + d4 + d16) + ad[21][i] * Math.sin((d5 - d4) + d16) + ad[22][i] * Math.sin(d5 - d4 - d16) + ad[23][i] * Math.sin(3D * d5 + d4) + ad[24][i] * Math.sin(4D * d5);
        } else
        {
            double d10 = (((0.0030599999999999998D - 0.00038000000000000002D * d9 * Math.cos(d4)) + 0.00025999999999999998D * Math.cos(d5)) - 2.0000000000000002E-005D * Math.cos(d5 - d4)) + 2.0000000000000002E-005D * Math.cos(d5 + d4) + 2.0000000000000002E-005D * Math.cos(d16);
            d7 = (((((((((((-0.62800999999999996D * Math.sin(d5) + 0.17172000000000001D * Math.sin(d4) * d9) - 0.01183D * Math.sin(d5 + d4) * d9) + 0.0086199999999999992D * Math.sin(d15) + 0.0080400000000000003D * Math.sin(d16) + 0.0045399999999999998D * Math.sin(d5 - d4) * d9 + 0.0020400000000000001D * Math.sin(d14) * d9 * d9) - 0.0018D * Math.sin(d5 - d16) - 0.00069999999999999999D * Math.sin(d5 + d16) - 0.00040000000000000002D * Math.sin(3D * d5) - 0.00034000000000000002D * Math.sin(d15 - d4) * d9) + 0.00032000000000000003D * Math.sin(d4 + d16) * d9 + 0.00032000000000000003D * Math.sin(d4 - d16) * d9) - 0.00027999999999999998D * Math.sin(d5 + d14) * d9 * d9) + 0.00027D * Math.sin(d15 + d4) * d9) - 0.00017000000000000001D * Math.sin(d8) - 5.0000000000000002E-005D * Math.sin(d5 - d4 - d16)) + 4.0000000000000003E-005D * Math.sin(d15 + d16)) - 4.0000000000000003E-005D * Math.sin(d5 + d4 + d16)) + 4.0000000000000003E-005D * Math.sin(d5 - d14) + 3.0000000000000001E-005D * Math.sin((d5 + d4) - d16) + 3.0000000000000001E-005D * Math.sin(3D * d4) + 2.0000000000000002E-005D * Math.sin(d15 - d16) + 2.0000000000000002E-005D * Math.sin((d5 - d4) + d16)) - 2.0000000000000002E-005D * Math.sin(3D * d5 + d4);
            if(d2 == 0.25D)
                d7 -= d10;
            if(d2 == 0.75D)
                d7 += d10;
        }
        d7 += 0.00032499999999999999D * Math.sin(d17) + 5.5999999999999999E-005D * Math.sin(d24) + 0.000165D * Math.sin(d18) + 4.6999999999999997E-005D * Math.sin(d25) + 0.000164D * Math.sin(d19) + 4.1999999999999998E-005D * Math.sin(d26) + 0.000126D * Math.sin(d20) + 4.0000000000000003E-005D * Math.sin(d27) + 0.00011D * Math.sin(d21) + 3.6999999999999998E-005D * Math.sin(d28) + 6.2000000000000003E-005D * Math.sin(d22) + 3.4999999999999997E-005D * Math.sin(d29) + 6.0000000000000002E-005D * Math.sin(d23) + 2.3E-005D * Math.sin(d30);
        return d7;
    }

    public void getApogeePerigee()
    {
        double d1 = (getDateAndTime() - 1999.97D) * 13.2555D;
        int i = (int)d1;
        lunarPerigee = CalDate(jdXgee(i));
        lunarPerigee = lunarPerigee.substring(0, lunarPerigee.length() - 5);
        if(lunarPerigee.length() == 11)
            lunarPerigee = lunarPerigee.substring(0, 6) + "0" + lunarPerigee.substring(6, 11);
        lunarApogee = CalDate(jdXgee((double)i - 0.5D));
        lunarApogee = lunarApogee.substring(0, lunarApogee.length() - 5);
        if(lunarApogee.length() == 11)
            lunarApogee = lunarApogee.substring(0, 6) + "0" + lunarApogee.substring(6, 11);
    }

    public double jdXgee(double d1)
    {
        double d3 = d1 / 1325.55D;
        double d4 = d3 * d3;
        double d5 = d4 * d3;
        double d6 = d5 * d3;
        double d2 = ((2451534.6697999998D + 27.55454988D * d1) - 0.00068860000000000004D * d4 - 1.0979999999999999E-006D * d5) + 5.2000000000000002E-009D * d6;
        double d7 = reduce(rad(((171.9179D + 335.9106046D * d1) - 0.010024999999999999D * d4 - 1.1559999999999999E-005D * d5) + 5.5000000000000003E-008D * d6));
        double d8 = reduce(rad((347.34769999999997D + 27.157772099999999D * d1) - 0.00083230000000000001D * d4 - 9.9999999999999995E-007D * d5));
        double d9 = reduce(rad((316.61090000000002D + 364.52879109999998D * d1) - 0.012513099999999999D * d4 - 1.4800000000000001E-005D * d5));
        double d13 = 2D * d7;
        double d15 = 2D * d9;
        double d16 = 2D * d8;
        double d14 = 4D * d7;
        double d17 = 6D * d7;
        double d10;
        if(d1 - (double)(int)d1 != 0.0D)
        {
            d10 = (((((((((0.43919999999999998D * Math.sin(d13) + 0.068400000000000002D * Math.sin(d14) + (0.045600000000000002D - 0.00011D * d3) * Math.sin(d8) + (0.042599999999999999D - 0.00011D * d3) * Math.sin(d13 - d8) + 0.0212D * Math.sin(d15)) - 0.0189D * Math.sin(d7)) + 0.0144D * Math.sin(d17) + 0.011299999999999999D * Math.sin(d14 - d8) + 0.0047000000000000002D * Math.sin(d13 + d15) + 0.0035999999999999999D * Math.sin(d7 + d8) + 0.0035000000000000001D * Math.sin(8D * d7) + 0.0033999999999999998D * Math.sin(d17 - d8)) - 0.0033999999999999998D * Math.sin(d13 - d15)) + 0.0022000000000000001D * Math.sin(d13 - d16)) - 0.0016999999999999999D * Math.sin(3D * d7)) + 0.0012999999999999999D * Math.sin(d14 + d15) + 0.0011000000000000001D * Math.sin(8D * d7 - d8) + 0.001D * Math.sin(d14 - d16) + 0.00089999999999999998D * Math.sin(10D * d7) + 0.00069999999999999999D * Math.sin(3D * d7 + d8) + 0.00059999999999999995D * Math.sin(d16) + 0.00050000000000000001D * Math.sin(d13 + d8) + 0.00050000000000000001D * Math.sin(d13 + d16) + 0.00040000000000000002D * Math.sin(d17 + d15) + 0.00040000000000000002D * Math.sin(d17 - 2D * d8) + 0.00040000000000000002D * Math.sin(10D * d7 - d8)) - 0.00040000000000000002D * Math.sin(5D * d7) - 0.00040000000000000002D * Math.sin(d14 - d15)) + 0.00029999999999999997D * Math.sin(d15 + d8) + 0.00029999999999999997D * Math.sin(12D * d7) + 0.00029999999999999997D * Math.sin((d13 + d15) - d8)) - 0.00029999999999999997D * Math.sin(d7 - d8);
            double d11 = (((((3245.2510000000002D - 9.1460000000000008D * Math.cos(d13) - 0.84099999999999997D * Math.cos(d7)) + 0.69699999999999995D * Math.cos(d15) + (-0.65600000000000003D + 0.0016000000000000001D * d3) * Math.cos(d8) + 0.35499999999999998D * Math.cos(d14) + 0.159D * Math.cos(d13 - d8) + 0.127D * Math.cos(d7 + d8) + 0.065000000000000002D * Math.cos(d14 - d8) + 0.051999999999999998D * Math.cos(d17) + 0.042999999999999997D * Math.cos(d13 + d8) + 0.031D * Math.cos(d13 + d15)) - 0.023D * Math.cos(d13 - d15)) + 0.021999999999999999D * Math.cos(d13 - d16) + 0.019D * Math.cos(d13 + d16)) - 0.016D * Math.cos(d16)) + 0.014D * Math.cos(d17 - d8) + 0.01D * Math.cos(8D * d7);
            ApogeeDistance = (long)(6378.1400000000003D / Math.sin(rad(d11 / 3600D)));
        } else
        {
            d10 = (((((((((((((((((((((((((((((-1.6769000000000001D * Math.sin(d13) + 0.45889999999999997D * Math.sin(d14)) - 0.18559999999999999D * Math.sin(d17)) + 0.088300000000000003D * Math.sin(8D * d7) + (-0.077299999999999994D + 0.00019000000000000001D * d3) * Math.sin(d13 - d8) + (0.050200000000000002D - 0.00012999999999999999D * d3) * Math.sin(d8)) - 0.045999999999999999D * Math.sin(10D * d7)) + (0.042200000000000001D - 0.00011D * d3) * Math.sin(d14 - d8)) - 0.025600000000000001D * Math.sin(d17 - d8)) + 0.0253D * Math.sin(12D * d7) + 0.023699999999999999D * Math.sin(d7) + 0.016199999999999999D * Math.sin(8D * d7 - d8)) - 0.014500000000000001D * Math.sin(14D * d7)) + 0.0129D * Math.sin(d15)) - 0.0112D * Math.sin(3D * d7) - 0.0104D * Math.sin(10D * d7 - d8)) + 0.0086D * Math.sin(16D * d7) + 0.0068999999999999999D * Math.sin(12D * d7 - d8) + 0.0066D * Math.sin(5D * d7)) - 0.0053D * Math.sin(d13 + d15) - 0.0051999999999999998D * Math.sin(18D * d7) - 0.0045999999999999999D * Math.sin(14D * d7 - d8) - 0.0041000000000000003D * Math.sin(7D * d7)) + 0.0040000000000000001D * Math.sin(d13 + d8) + 0.0032000000000000002D * Math.sin(20D * d7)) - 0.0032000000000000002D * Math.sin(d7 + d8)) + 0.0030999999999999999D * Math.sin(16D * d7 - d8)) - 0.0028999999999999998D * Math.sin(d14 + d8)) + 0.0027000000000000001D * Math.sin(9D * d7) + 0.0027000000000000001D * Math.sin(d14 + d15)) - 0.0027000000000000001D * Math.sin(d13 - d16)) + 0.0023999999999999998D * Math.sin(d14 - d16)) - 0.0020999999999999999D * Math.sin(d17 - d16) - 0.0020999999999999999D * Math.sin(22D * d7) - 0.0020999999999999999D * Math.sin(18D * d7 - d8)) + 0.0019D * Math.sin(d17 + d8)) - 0.0018D * Math.sin(11D * d7) - 0.0014D * Math.sin(8D * d7 + d8) - 0.0014D * Math.sin(d14 - d15) - 0.0014D * Math.sin(6D * d7 + d15)) + 0.0014D * Math.sin(3D * d7 + d8)) - 0.0014D * Math.sin(5D * d7 + d8)) + 0.0012999999999999999D * Math.sin(13D * d7) + 0.0012999999999999999D * Math.sin(20D * d7 - d8) + 0.0011000000000000001D * Math.sin(3D * d7 + d16)) - 0.0011000000000000001D * Math.sin((d14 + d15) - d16) - 0.001D * Math.sin(d7 + d16) - 0.00089999999999999998D * Math.sin(22D * d7 - d8) - 0.00080000000000000004D * Math.sin(4D * d9)) + 0.00080000000000000004D * Math.sin(d17 - d15) + 0.00080000000000000004D * Math.sin((d13 - d15) + d8) + 0.00069999999999999999D * Math.sin(d16) + 0.00069999999999999999D * Math.sin(d15 - d8) + 0.00069999999999999999D * Math.sin(d13 + 4D * d9)) - 0.00059999999999999995D * Math.sin(d15 - d16) - 0.00059999999999999995D * Math.sin((d13 - d15) + d16)) + 0.00059999999999999995D * Math.sin(24D * d7) + 0.00050000000000000001D * Math.sin(d14 - 4D * d9) + 0.00050000000000000001D * Math.sin(d13 + d16)) - 0.00040000000000000002D * Math.sin(d7 - d8);
            double d12 = (((((((((((((((((((((((((((3629.2150000000001D + 63.223999999999997D * Math.cos(d13)) - 6.9900000000000002D * Math.cos(d14)) + (2.8340000000000001D - 0.0071000000000000004D * d3) * Math.cos(d13 - d8) + 0.19270000000000001D * Math.cos(d17)) - 1.2629999999999999D * Math.cos(d7) - 0.70199999999999996D * Math.cos(8D * d7)) + (0.69599999999999995D - 0.0016999999999999999D * d3) * Math.cos(d8)) - 0.68999999999999995D * Math.cos(d15)) + (-0.629D + 0.0016000000000000001D * d3) * Math.cos(d14 - d8)) - 0.39200000000000002D * Math.cos(d13 - d15)) + 0.29699999999999999D * Math.cos(10D * d7) + 0.26000000000000001D * Math.cos(d17 - d8) + 0.20100000000000001D * Math.cos(3D * d7)) - 0.161D * Math.cos(d13 + d8)) + 0.157D * Math.cos(d7 + d8)) - 0.13800000000000001D * Math.cos(12D * d7) - 0.127D * Math.cos(8D * d7 - d8)) + 0.104D * Math.cos(d13 + d15) + 0.104D * Math.cos(d13 - d16)) - 0.079000000000000001D * Math.cos(5D * d7)) + 0.068000000000000005D * Math.cos(14D * d7) + 0.067000000000000004D * Math.cos(10D * d7 - d8) + 0.053999999999999999D * Math.cos(d14 + d8)) - 0.037999999999999999D * Math.cos(12D * d7 - d8)) + 0.036999999999999998D * Math.cos(7D * d7)) - 0.036999999999999998D * Math.cos(d14 + d15) - 0.035000000000000003D * Math.cos(16D * d7) - 0.029999999999999999D * Math.cos(3D * d7 + d8)) + 0.029000000000000001D * Math.cos(d7 - d8)) - 0.025000000000000001D * Math.cos(d17 + d8)) + 0.023D * Math.cos(d16) + 0.023D * Math.cos(14D * d7 - d8)) - 0.023D * Math.cos(d13 + d16)) + 0.021999999999999999D * Math.cos(d17 - d16)) - 0.021000000000000001D * Math.cos(d13 - d15 - d8) - 0.02D * Math.cos(9D * d7)) + 0.019D * Math.cos(18D * d7) + 0.017000000000000001D * Math.cos(d17 + d15) + 0.014D * Math.cos(d15 - d8)) - 0.014D * Math.cos(16D * d7 - d8)) + 0.012999999999999999D * Math.cos(d14 - d15) + 0.012D * Math.cos(8D * d7 + d8) + 0.010999999999999999D * Math.cos(11D * d7) + 0.01D * Math.cos(5D * d7 + d8)) - 0.01D * Math.cos(20D * d7);
            PerigeeDistance = (long)(6378.1400000000003D / Math.sin(rad(d12 / 3600D)));
        }
        d2 += d10;
        return d2;
    }

    public double getMoonJD(double d1, double d2)
    {
        double d4 = d1 / 1236.8499999999999D;
        double d5 = d4 * d4;
        double d6 = d5 * d4;
        double d7 = d6 * d4;
        double d3 = ((2451550.0976499999D + 29.530588853000001D * d1 + 0.0001337D * d5) - 1.4999999999999999E-007D * d6) + 7.2999999999999996E-010D * d7 + calculateMajorPhase(d1, d2, d4);
        return d3;
    }

    public LunarPhases()
    {
        borderWidth = 4;
        gmt = "";
        monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
        PhaseCounter = 75;
        isRunning = false;
        about = false;
    }
}